﻿using MengLin.OOP.DesignPattern.WMS_LC.Implements;
using MengLin.OOP.DesignPattern.WMS_LC.Interface;
using MengLin.OOP.DesignPattern.WMS_LC.Interface.Observer;
using MengLin.OOP.DesignPattern.WMS_LC.Interface.Subject;
using MengLin.OOP.DesignPattern.WMS_LC.Scheduler;
using MengLin.OOP.DesignPattern.WMS_LC.Scheduler.Implements;
using System;
using System.Threading;

namespace MengLin.OOP.DesignPattern.WMS_LC
{
    class Program
    {
        static void Main(string[] args)
        {
            #region Version1.调度器Scheduler和传感器的依赖，调度器Scheduler和用户界面的依赖(而且是直接依赖的关系)
            //{
            //    TimerCallback folderCallback = new TimerCallback(StartVerionOneScheduler);
            //    System.Threading.Timer timerFolder = new System.Threading.Timer(folderCallback, "开始调度", 0, 10000);
            //}
            #endregion

            #region Version2.调度器Scheduler和用户界面的解耦(调度器Scheduler不知道用户界面的存在)
            //{
            //    //被观察者(这里特指Nimbus1.0硬件平台的温度传感器)
            //    ISubject iTemperatureSensor = new Nimbus1_0TemperatureSensor();
            //    //被观察者(这里是特指Nimbus1.0硬件平台的气压传感器)
            //    ISubject iBarometricPressureSensor = new Nimbus1_0BarometricPressureSensor();

            //    //观察者(这里特指电视机显示器和电脑显示器，用户界面)
            //    IObserver tv = new TVMonitoringScreen();
            //    IObserver computer = new ComputerMonitoringScreen();

            //    //给温度传感器观察者列表里注册观察者(TV,Computer)
            //    iTemperatureSensor.AddObserver(tv);
            //    iTemperatureSensor.AddObserver(computer);

            //    //给气压传感器的观察者列表里注册观察者(TV,Computer)
            //    iBarometricPressureSensor.AddObserver(tv);
            //    iBarometricPressureSensor.AddObserver(computer);

            //    //调度器
            //    AbstractScheduler scheduler = new VerionTwoScheduler();
            //    scheduler.TemperatureSensor = (AbstractTemperatureSensor)iTemperatureSensor;
            //    scheduler.BarometricPressureSensor = (AbstractBarometricPressureSensor)iBarometricPressureSensor;

            //    scheduler.Tic();
            //}
            #endregion

            #region Version3.调度器Scheduler和传感器的解耦(调度器Scheduler只管调度就好了,调度器Scheduler不知道用户界面和传感器的存在)
            {
                //被观察者(这里特指Nimbus1.0硬件平台的温度传感器)
                ISubject iTemperatureSensor = new Nimbus1_0TemperatureSensor();

                //被观察者(这里是特指Nimbus1.0硬件平台的气压传感器)
                ISubject iBarometricPressureSensor = new Nimbus1_0BarometricPressureSensor();
                //调度器
                AbstractScheduler alarmClock = new AlarmClock();

                //观察者(这里特指电视机显示器和电脑显示器，用户界面)
                IObserver tv = new TVMonitoringScreen();
                IObserver computer = new ComputerMonitoringScreen();

                //给温度传感器观察者列表里注册观察者(TV,Computer)
                iTemperatureSensor.AddObserver(tv);
                iTemperatureSensor.AddObserver(computer);

                //给气压传感器的观察者列表里注册观察者(TV,Computer)
                iBarometricPressureSensor.AddObserver(tv);
                iBarometricPressureSensor.AddObserver(computer);

                alarmClock.Tic();
            }
            #endregion

            #region Version4.上端调用的时候，多处指定了1.0硬件平台，需要提升为指定1次1.0硬件平台就行了
            {

            }
            #endregion
            Console.Read();
        }

        /// <summary>
        /// 开始调度(每轮询10秒调度)
        /// </summary>
        /// <param name="state"></param>
        private static void StartVerionOneScheduler(object state)
        {
            AbstractScheduler scheduler = new VerionOneScheduler();
            scheduler.TemperatureSensor = new Nimbus1_0TemperatureSensor();
            scheduler.Tic();
        }
    }
}
